using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region SurveyAnswer

	/// <summary>
	/// SurveyAnswer object for NHibernate mapped table 'SurveyAnswer'.
	/// </summary>
	[Serializable]
	public class SurveyAnswer : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _score;
		protected string _comment;
		protected CustomerSurvey _customerSurvey;
		protected SurveyQuestion _surveyQuestion;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public SurveyAnswer() { }

		public SurveyAnswer( string score, string comment, CustomerSurvey customerSurvey, SurveyQuestion surveyQuestion )
		{
			this._score = score;
			this._comment = comment;
			this._customerSurvey = customerSurvey;
			this._surveyQuestion = surveyQuestion;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string Score
		{
			get { return _score; }
			set
			{
				if ( value != null && value.Length > 10)
					throw new ArgumentOutOfRangeException("Invalid value for Score", value, value.ToString());
				_score = value;
			}
		}

		public string Comment
		{
			get { return _comment; }
			set
			{
				if ( value != null && value.Length > 100)
					value = value.Substring(0, 100 );
				_comment = value;
			}
		}

		public CustomerSurvey CustomerSurvey
		{
			get { return _customerSurvey; }
			set { _customerSurvey = value; }
		}

		public SurveyQuestion SurveyQuestion
		{
			get { return _surveyQuestion; }
			set { _surveyQuestion = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is SurveyAnswer))
				throw new InvalidCastException("This object is not of type SurveyAnswer");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((SurveyAnswer)obj).Id);
					break;
				case "Score":
						relativeValue = ( this.Score != null ) ? this.Score.CompareTo(((SurveyAnswer)obj).Score) : -1;
					break;
				case "Comment":
						relativeValue = ( this.Comment != null ) ? this.Comment.CompareTo(((SurveyAnswer)obj).Comment) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (SurveyAnswer.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
